
#include <Point.h>

#define PI 3.14159265

Point::Point()
{
	x = y = z = 0.0f;
}

Point::Point(float x, float y, float z)
{
	this->x = x;
	this->y = y;
	this->z = z;
}

Point Point::operator = (const Point & newPoint)
{
	this->x = newPoint.x;
	this->y = newPoint.y;
	this->z = newPoint.z;

	return *this;
}

//it allows to add two vectors
Point operator + (const Point& a, const Point& b)
{
	return Point(a.x + b.x, a.y + b.y, a.z + b.z );
}

//it allows to add two vectors
Point operator - (const Point& a, const Point& b)
{
	return Point(a.x - b.x, a.y - b.y, a.z - b.z );
}

/*
void Point::rotatePoint(int rotx, int roty, int rotz) {

	float xRotRad = 0;
	float yRotRad = 0;
	float zRotRad = 0;

	Matrix44 rotationMatrix;

	for (int i = 0; i < rotx; i++) {
		xRotRad += PI / 2;
	}

	rotationMatrix.setRotation(xRotRad, Point(1, 0, 0));
	*this = rotationMatrix.rotateVector(*this);

	for (int i = 0; i < roty; i++) {
		yRotRad += PI / 2;
	}

	rotationMatrix.setRotation(yRotRad, Point(0, 1, 0));
	*this = rotationMatrix.rotateVector(*this);

	for (int i = 0; i < rotz; i++) {
		zRotRad += PI / 2;
	}

	rotationMatrix.setRotation(zRotRad, Point(0, 0, 1));
	*this = rotationMatrix.rotateVector(*this);

}*/

void Point::rotateCubePoint(int rotx, int roty, int rotz)
{

	double tmpZ = z;
	for(int i = 0; i < rotz; i++)
	{
		x -= 0.5;
		y -= 0.5;
		z -= 0.5;
		*this = crossVector(Point(0,0,1));
		x += 0.5;
		y += 0.5;
		z = tmpZ;
	}

	double tmpY = y;
	for(int i = 0; i < roty; i++)
	{
		x -= 0.5;
		y -= 0.5;
		z -= 0.5;
		*this = crossVector(Point(0,1,0));
		x =
		x += 0.5;
		y = tmpY;
		z += 0.5;
	}

	double tmpX = x;
	for(int i = 0; i < rotx; i++)
	{
		x -= 0.5;
		y -= 0.5;
		z -= 0.5;
		*this = crossVector(Point(-1,0,0));
		x = tmpX;
		y += 0.5;
		z += 0.5;
	}



}
Point Point::crossVector(const Point & point2)
	{
		return Point(y * point2.z - z * point2.y,
				z * point2.x - x * point2.z,
				x * point2.y - y * point2.x);
	}
